﻿using System;

namespace TinyCms.Core
{
    /// <summary>
    /// 表示派生类都是可释放托管及非托管资源
    /// 注意继承<see cref="IDisposable"/>接口可使用using语句
    /// </summary>
    public abstract class DisposableObject:IDisposable
    {
        #region Finalization Constructs
        /// <summary>
        /// 析构中释放资源
        /// </summary>
        ~DisposableObject()
        {
            Dispose(false);
        }
        #endregion

        #region Protected Methods
        /// <summary>
        /// 是否显示的释放资源
        /// </summary>
        /// <param name="disposing"></param>
        protected abstract void Dispose(bool disposing);
        
        /// <summary>
        /// 显示释放资源
        /// </summary>
        protected void ExplicitDispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion

        #region IDisposable Members
        
        /// <summary>
        /// 可释放托管与非托管资源
        /// </summary>
        public void Dispose()
        {
            ExplicitDispose();
        }
        #endregion
    }
}
